def dfs(s, t):
    if s == t:
        print(a[0:n])
    else:
        for i in range(s, t + 1):
            a[s], a[i] = a[i], a[s]
            dfs(s + 1, t)
            a[s], a[i] = a[i], a[s]

a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
n = 4
dfs(0, n - 1)
